-
-
Notifications
You must be signed in to change notification settings - Fork 3k
zig fmt: canonicalize nested cast builtin order #24199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
b22a8a0 to
03fea83
Compare
3d1d91f to
0a86578
Compare
0a86578 to
7fbfc80
Compare
|
@Justus2308 what's the state of this PR? You've left a bunch of review comments which look like suggestions for yourself or something? |
|
Sorry, I'm not very familiar with the review process here/in general yet. Should I just apply the changes and add them in a separate commit here? Or should I amend my previous commits? |
|
Feel free to commit however you prefer -- we can always manually do any fixups when we go to merge. If it's all the same to you, here I'd probably prefer you keep exactly two commits and amend them appropriately, but whatever you choose to do is fine! |
7fbfc80 to
121031f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a proper review, just some light style suggestions
121031f to
7c35070
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, currently this doesn't handle parentheses between the casts (@ptrCast((@constCast(something)))) but it should be straightforward to add if it is even desired.
|
FWIW I think it was a bad decision of mine to allow |
|
Great, thanks for the review! Can somebody please restart the cancelled CI job I'm 99% confident it will pass :) |
imo the long term solution is to make |
|
I agree, though #114 should probably be implemented first otherwise a canonicalization removing all technically unnecessary parentheses would make math expressions involving more than a couple of operators even harder to look at... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting strategy -- took me a moment to properly understand -- but seems like it works fine. Thanks!
|
Oops, sorry, wrong button -- that was meant to be an "approve". |
Closes #24106
Searches for surrounding tokens tagged with
.builtinwhen a.builtin_...node whose main token ends in"Cast"is encountered and picks which one to render first according to the field order inCastKind. In case of a redundant casting operation (e.g.@ptrCast(@volatileCast(@ptrCast(...)))) no reordering is done for the entire nested chain.The canonical ordering is the one proposed by mlugg:
It can be changed by simply rearranging the fields of
CastKind(and adjusting the rendering order intranslate_c.removeCVQualifiersfor@constCast()/@volatileCast()and related tests).The first commit is the actual implementation,the second commit is the new ordering applied to affected source files.